<template>
  <div>
      <el-card class="box-card">
          <div slot="header" class="clearfix">
              <span> 筛选搜索</span>
          </div>
          <el-form ref="form" :model="name1">
              <el-form-item label="品牌名称" label-width="80px">
                  <el-input v-model="name1.name" style="width: 150px"></el-input>
              </el-form-item>
              <el-button style="float: right; padding: 3px 0" type="text" @click="findlist">查询结果</el-button>
          </el-form>
      </el-card>

      <br>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>数据列表</span>
        <el-button style="float: right; padding: 3px 0" type="text" @click="addbrand">添加</el-button>
      </div>
      <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 2200px">
        <el-table-column
          type="selection"
          width="55">
        </el-table-column>
        <el-table-column label="日期" >
          <template slot-scope="scope">{{ scope.row.id }}</template>
        </el-table-column>
        <el-table-column label="名称" >
          <template slot-scope="scope">{{ scope.row.name }}</template>
        </el-table-column>
        <el-table-column label="首字母" >
          <template slot-scope="scope">{{ scope.row.firstLetter }}</template>
        </el-table-column>
        <el-table-column label="排序">
          <template slot-scope="scope">{{ scope.row.sort }}</template>
        </el-table-column>
        <el-table-column label="品牌制造商" >
          <template slot-scope="scope">
            <el-switch v-model="scope.row.factoryStatus" @change="updateFactoryStatus(scope.row)" :active-value=1 :inactive-value=0></el-switch>
          </template>
        </el-table-column>
        <el-table-column label="是否显示" >
          <template slot-scope="scope">
            <el-switch v-model="scope.row.showStatus" @change="updateShowStatus(scope.row)" :active-value=1 :inactive-value=0></el-switch>
          </template>
        </el-table-column>
        <el-table-column label="相关">
          <template slot-scope="scope">
            商品：<span style="color: #00afff">{{ scope.row.productCount }}</span>
            评论：<span style="color: #00afff">{{ scope.row.productCommentCount }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handleEdit(scope.row)">编辑</el-button>
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-select>
      <el-option value="批量操作">批量操作</el-option>
      <el-option value="删除">删除</el-option>
    </el-select>
    <el-button style="background-color: #00afff">确定</el-button>
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        style="float: right; padding: 3px 0" type="text"
        :current-page="pageNum"
        :page-sizes="[5, 10, 15]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）,
//例如：import 《组件名称》 from '《组件路径》,
import {delect, findBrandList, updateFactoryStatus, updateShowStatus} from "@/api/product/brand";

export default {
    //import引入的组件需要注入到对象中才能使用"
    components: {},
    props: {},
    data() {
      //这里存放数据"

      return {
          tableData:{},
          name1:{
            name:''
          },
          pageNum:1,
          pageSize:3,
          total:1
      };
    },
    //计算属性 类似于data概念",
    computed: {},
    //监控data中的数据变化",
    watch: {},
    //方法集合",
    methods: {
      updateFactoryStatus(val){
        updateFactoryStatus(val.id,val.factoryStatus).then(
          res=>{
            this.$message.success(res.msg)
          }
        )
      },
      updateShowStatus(val){
        updateShowStatus(val.id,val.showStatus).then(
          res=>{
            this.$message.success(res.msg)
          }
        )
      },
      handleEdit(val){
        this.$router.push({path:'/product/updatebrand',query:{brand:val}})
      },
      handleDelete(val){
        delect(val).then(
            res=>{
              this.$message.success("删除成功")
              location.reload()
            }
        )
      },
      handleSizeChange(val) {
        this.pageSize=val
        this.findBrandList()
      },
      handleCurrentChange(val) {
        this.pageNum=val
        this.findBrandList()
      },
      findlist(){
          this.findBrandList()
      },
      addbrand(){
        this.$router.push('/product/addbrand')
      },
      findBrandList(){
        findBrandList(this.name1.name,this.pageNum,this.pageSize).then(
          res=>{
            console.log(res)
            this.tableData=res.data.rows
            this.total=res.data.total
          }
        )
      }
    },
    //生命周期 - 创建完成（可以访问当前this实例）",
    created() {
      this.findBrandList()
    },
    //生命周期 - 挂载完成（可以访问DOM元素）",
    mounted() {
    },
    beforeCreate() {
    }, //生命周期 - 创建之前",
    beforeMount() {
    }, //生命周期 - 挂载之前",
    beforeUpdate() {
    }, //生命周期 - 更新之前",
    updated() {
    }, //生命周期 - 更新之后",
    beforeDestroy() {
    }, //生命周期 - 销毁之前",
    destroyed() {
    }, //生命周期 - 销毁完成",
    activated() {
    } //如果页面有keep-alive缓存功能，这个函数会触发",
  };
</script>
<style scoped>

</style>
